home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / SORTTEXT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.4 KB  |  48 lines

  1. /*  sorttext.c - sort a text file ( lines of ASCII characters) */
  2. #include   "stdio.h"
  3. #include   "cminor.h"
  4. #include   "sorttext.h"
  5.  
  6. int  strcmp() ;         /* string compare function */
  7. FILE *do_open() ;        /* opens file and checks for errors */
  8.  
  9. main(argc,argv)
  10.   int    argc  ;         /* number of words in command ine */
  11.   char    *argv[] ;        /* pointers to each word */
  12.   {
  13.      /* check to see that file names were specified */
  14.      if( argc < 3 )
  15.     {  printf(" need file names \n") ;
  16.        printf(" USAGE: sortfile   input-file   output-file  \n") ;
  17.        exit(1) ;
  18.     }
  19.  
  20.      dosort(argv[1],argv[2]) ;    /* do the sort */
  21.   }
  22.  
  23.  
  24. int  dosort(fromfile,tofile)
  25.   char    fromfile[] ;        /* input for sort */
  26.   char    tofile[] ;        /* put the output here */
  27.   {
  28.      int   nrec ;
  29.      char  sarea[ SSIZE ] ;    /* storage area for text lines */
  30.      char  *p[ MAX_REC ]  ;    /* pointers to lines of text */
  31.      FILE  *infile ;        /* input file */
  32.  
  33.      infile = do_open(fromfile,"r") ;   /* open input file */
  34.      initfill(infile) ;     /* initialize for fillarea */
  35.                 /* read text file in storage area */
  36.      if( fillarea(sarea,SSIZE,p,MAX_REC,&nrec,infile) != AT_EOF)
  37.     {  printf("file too large") ;
  38.        exit(3) ;
  39.     }
  40.      do_close(infile,fromfile) ;
  41.  
  42.      memsort(p,nrec,strcmp) ;    /* sort using string compare fun. */
  43.      outfile(p,nrec,tofile) ;    /* write sorted lines out */
  44.   }
  45.  
  46.  
  47.  
  48.